/*
 * $Id$
 * Sleeper
 *
 * Created by Jon Gordon on 11/24/08
 * Copyright Jon Gordon.  All rights reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining 
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including 
 * without limitation the rights to use, copy, modify, merge, publish, 
 * distribute, sublicense, and/or sell copies of the Software, and to 
 * permit persons to whom the Software is furnished to do so, subject to 
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


#import "QEExToken.h"


@implementation QEExToken
#pragma mark LIFECYCLE METHODS
- (id)initWithValue:(NSString *)newValue atPosition:(unsigned int)newPosition
{
//    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    self = [super init];
    if (nil != self) {
        value = [newValue copy];
        position = newPosition;
    } // if
    return self;
} // initWithValue:atPosition:

- (id)init
{
//    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [self initWithValue:nil atPosition:0];
} // init

- (void)dealloc
{
//    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    [value release];
    [super dealloc];
} // dealloc

- (id)copyWithZone:(NSZone *)zone
{
//    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [self retain];
} // copyWithZone:

- (unsigned int)hash
{
//    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    static const unsigned int HASH_BASE = 17;
    static const unsigned int HASH_FACTOR = 37;
    
    unsigned int result = HASH_BASE;
    result = (result * HASH_FACTOR) + [[self value] hash];
    result = (result * HASH_FACTOR) + [self position];
    
    return result * HASH_FACTOR;
} // hash

- (BOOL)isEqual:(id)anObject
{
//    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return ((self == anObject) ||
            ([[self value] isEqual:[anObject value]] &&
             ([self position] == [anObject position])));
} // isEqual:

- (NSString *)description
{
    return [NSString stringWithFormat:@"%@; value: %@, position: %u",
            [super description],
            value, position];
} // description


#pragma mark ACCESSORS
- (NSString *)value
{
//    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [[value retain] autorelease];
} // value

- (unsigned int)position
{
//    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return position;
} // position
@end
